<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 构造函数
        // function Student(name,age){
        //     this.name = name;
        //     this.age = age;
            
        // }
        // Student.prototype.song = function(){
        //     console.log(`你好我是${this.name},我会唱歌`);
        // }
        // var xiaoming = new Student("小明",10);
        // console.log(xiaoming);
        // xiaoming.song()

        //类，相当于构造函数
        // class Student {
        //     constructor(name,age){
        //         this.name = name;
        //         this.age = age;
        //     }
        //     song(){
        //         console.log(`你好我是${this.name},我会唱歌`);
        //     }
        //     say(){
        //         console.log(`你好我是${this.name}`);
        //     }
        // }

        // let zhangsan = new Student("张三",18);

        // zhangsan.song();
        // zhangsan.say();
    // 也可以通过Object.assign()方法，一次性向类中添加多个方法
    class Person {
            constructor(name,age){
                this.name = name;
                this.age = age;
            }
        }
        Object.assign(Person.prototype,{
            sayName(){
                return this.name;
            },
            sayAge(){
                return this.age
            }
        })
    p1 = new Person("张三",10);
    console.log(p1.sayName())
    </script>
</body>
</html>